package org.niu.dp;

public class maxProfit {
    public int maxProfit(int[] prices) {
        // write code here
        int ans = 0;
        int minx = Integer.MAX_VALUE / 2;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] > minx) {
                if (ans < (prices[i] - minx)) {
                    ans = prices[i] - minx;
                }
            }
            if (prices[i] < minx) {
                minx = prices[i];
            }
        }
        return ans;
    }
}